package com.cat.greedyAlgorithm;

import java.util.Arrays;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/minimum-increment-to-make-array-unique/description/
 * @create 2025/8/21 16:46
 * @since JDK17
 */

public class Solution09 {
    public int minIncrementForUnique(int[] nums) {
        Arrays.sort(nums);
        int ans = 0, n = nums.length;
        for (int i = 1, t; i < n; i++) {
            t = nums[i - 1] + 1 - nums[i];
            if (t > 0) {
                ans += t;
                nums[i] += t;
            }
        }
        return ans;
    }
}
